package com.cc.visitor.controller;

import com.cc.alltype.ResponseResult;
import com.cc.visitor.entity.Visit;
import com.cc.visitor.service.CallProcedureService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.util.Map;

/**
 * @author chanchaw
 * @create 2024-11-20 10:32
 */
@CrossOrigin
@RestController
@RequestMapping("/call")
public class CallProcedureController {
    @Autowired
    private CallProcedureService service;

    @PostMapping("/getVisitorTop3")
    public ResponseResult getVisitorTop3(@RequestBody Map<String,String> params){
        String openId = params.get("openId");
        return ResponseResult.ok(service.getVisitorTop3(openId));
    }
    @PostMapping("/getUnFinishedVisit")
    public ResponseResult getUnFinishedVisit(@RequestBody String unionId){
        return ResponseResult.ok(service.getUnFinishedVisit(unionId));
    }

    /**
     * 查询获取指定访客指定日期的所有访单
     * @param record 只需要方法内的3个属性：visitor_union_id,start_time,finished
     * @return
     */
    @PostMapping("/getVisitorDayRecords")
    public ResponseResult getVisitorDayRecords(@RequestBody Visit record){
        String unionId = record.getVisitorUnionId();
        String targetDay = record.getStartTime().toString();
        Integer finished = record.getFinished();
        return ResponseResult.ok(service.getVisitorDayRecords(unionId,targetDay,finished));
    }
    @PostMapping("/getVisitorDayRecords8VisitorName")
    public ResponseResult getVisitorDayRecords8VisitorName(@RequestBody Visit record){
        String visitorRealName = record.getVisitorRealName();
        String targetDay = record.getStartTime().toString();
        Integer finished = record.getFinished();
        return ResponseResult.ok(service.getVisitorDayRecords8VisitorName(visitorRealName,targetDay,finished));
    }
    @PostMapping("/getRejectVisit")
    public ResponseResult getUnFinishedVisit(@RequestBody Map<String, LocalDate> params){
        LocalDate sdate = params.get("sdate");
        LocalDate edate = params.get("edate");
        return ResponseResult.ok(service.getRejectVisit(sdate,edate));
    }
}
